module DateUtil

  def self.iterate_years(base_year = last_valid_year, years = 5)
    last_years(base_year, years).each do |year|
      yield year
    end
  end

  def self.iterate_months
    I18n.t('date.abbr_month_names').each_with_index do |month, i|
      yield month, i if month
    end
  end

  def self.last_years(base_year = last_valid_year, years = 5)
    Array.new(years) { |i| base_year - i }
  end

  def self.last_valid_year
    now = Time.now
    year = now.year
    year -= 1 if now.month == 1
    return year
  end

end
